﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Controls_Header : UserControlBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LinkButton lnkUserName = LoginView1.FindControl("lnkUserName") as LinkButton;
            if (lnkUserName != null)
            {
                if (!string.IsNullOrEmpty(UserName))
                {
                    lnkUserName.Text = UserName;
                }
                else
                {
                    lnkUserName.Visible = false;
                }
            }
            ImageButton imgUser = LoginView1.FindControl("imgUser") as ImageButton;
            if (imgUser != null)
            {
                if (!string.IsNullOrEmpty(ImageName))
                {
                    if (ImageName == "NoImage")
                    {
                        imgUser.ImageUrl = ResolveUrl("~/UserImage/image_missing.jpg");
                    }
                    else
                    {
                        imgUser.ImageUrl = ResolveUrl("~/UserImage/" + ImageName);
                    }
                }
                else
                {
                    imgUser.ImageUrl = ResolveUrl("~/UserImage/image_missing.jpg");
                }
            }

        }
    }
    protected void Login_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Login.aspx");
    }
    protected void Logout_Click(object sender, EventArgs e)
    {
        Session.Abandon();
        FormsAuthentication.SignOut();
        FormsAuthentication.RedirectToLoginPage();
    }
    protected void MyProfile_Click(object sender, EventArgs e)
    {
        if (UserID.HasValue)
        {
            Response.Redirect("~/UserDetails.aspx");
        }
    }
    protected void MyInBox_Click(object sender, EventArgs e)
    {
        if (UserID.HasValue)
        {
            Response.Redirect("~/PrivateMessages.aspx");
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/SearchResult.aspx?SearchText=" + txtSearch.Text);
    }
}
